<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonModule for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace TtkCompress\Controller;

use Zend\Filter\Compress\Zip;

use Zend\Mvc\Controller\AbstractActionController;

class TtkZipController extends AbstractActionController
{
    public function indexAction()
    {
        return array();
    }

    public function createZipAction()
    {
        if($this->getRequest()->isPost())
        {
        	$name = $this->params()->fromPost('name');
        	
        	$src = ROOT_PATH.'/develop/TtkCompress/data/zip/input/'.$name;
        	
        	$des = ROOT_PATH.'/develop/TtkCompress/data/zip/archive/';
        	
        	if(!is_dir($des.$name.'.zip'))
        	{
        		fopen($des.$name.'.zip', 'w');
        	}
        	
        	$options = array(
		        'archive' => $des.$name.'.zip',
		        'target'  => src,
		    );
        	
        	$zipEngine = new Zip($options);
        	
        	$zipEngine->compress($src);
        	
        }
        return array();
    }
    
    public function extractZipAction()
    {
    	if($this->getRequest()->isPost())
    	{
    		$name = $this->params()->fromPost('name');
    		
    		$src = ROOT_PATH.'/develop/TtkCompress/data/zip/input/'.$name.'.zip';
    		
    		$des = ROOT_PATH.'/develop/TtkCompress/data/zip/extracted';
    		 
    		if(!is_dir($des))
    			{
    				mkdir($des);
    			}
    			
    			$options = array(
    					'archive' => $src,
    					'target'  => $des,
    			);
    			
    			$zipEngine = new Zip($options);
    			 
    			$zipEngine->decompress($src);
    		
    	}
    	return array();
    }
}
